package cn.tedu.ivos.geofence.controllor;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceParam;
import cn.tedu.ivos.geofence.pojo.dto.GeofenceQuery;
import cn.tedu.ivos.geofence.pojo.vo.GeofenceVO;
import cn.tedu.ivos.geofence.service.GeofenceService;
import cn.tedu.ivos.vehicle.service.impl.VehicleServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/geofence")
public class GeofenceController {
    @Autowired
    private GeofenceService geofenceService;
    @Autowired
    private VehicleServiceImpl vehicleServiceImpl;

    @GetMapping("select")
    public JsonResult selectGeofence(GeofenceQuery geofenceQuery){
        log.debug("查询电子围栏：geofenceQuery={}",geofenceQuery);
        List<GeofenceVO> list =  geofenceService.selectGeofence(geofenceQuery);
        return  JsonResult.ok(list);
    }

    @PostMapping("save")
    public JsonResult saveGeofence(GeofenceParam geofenceParam){
        log.debug("保存电子围栏：geofenceParam={}",geofenceParam);
        geofenceService.saveGeofence(geofenceParam);
        return JsonResult.ok();
    }

    @PostMapping("update/{id}/{status}")
    public JsonResult changeStatus(@PathVariable Long id,@PathVariable String status){
        log.debug("修改围栏状态：id={},status={}",id,status);
        geofenceService.changeStatus(id,status);
        return  JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult delete(@PathVariable Long id){
        log.debug("删除围栏：id={}",id);
        geofenceService.deleteGeo(id);
        return JsonResult.ok();
    }

}
